import { ParseIntPipe, Query } from '@nestjs/common';
import { Body, Controller, DefaultValuePipe, Get, Post } from '@nestjs/common';
import { PermissionMeta } from 'src/decorators/permission.meta';
import { PermissionModule } from 'src/decorators/permission.module';
import { RedisClientService } from 'src/modules/shared/redis-utils/redis-client/redis-client.service';
import { AccountService } from '../../services/account/account.service';
import { CreateAccountDto } from './dto/create.account.dto';

// @PermissionModule('账号模块')
@Controller('account')
export class AccountController {
  constructor(
    private readonly accountService: AccountService,
    private readonly redisClientService: RedisClientService
  ) {}

  // @PermissionMeta('创建账号')
  @PermissionModule('账号模块')
  @Post()
  async createAccount(@Body() data: CreateAccountDto) {
    return await this.accountService.createAccount(data);
  }

  @PermissionMeta('分页获取账号')
  @Get()
  async accountList(@Query('pageSize', new DefaultValuePipe(5), ParseIntPipe) pageSize: number) {
    console.log(pageSize, '=====');
    this.redisClientService.redisClient.set('name', 'hello');
    return await this.accountService.accountList();
  }
}
